package com.ruoyi.law.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.law.domain.ContentCaseFlow;
import com.ruoyi.law.service.IContentCaseFlowService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 流程主体Controller
 *
 * @author gyl
 * @date 2025-02-27
 */
@RestController
@RequestMapping("/contentCaseFlow/contentCaseFlow")
public class ContentCaseFlowController extends BaseController
{
    @Autowired
    private IContentCaseFlowService contentCaseFlowService;

    /**
     * 查询流程主体列表
     */
    @PreAuthorize("@ss.hasPermi('contentCaseFlow:contentCaseFlow:list')")
    @GetMapping("/list")
    public TableDataInfo list(ContentCaseFlow contentCaseFlow)
    {
        startPage();
        List<ContentCaseFlow> list = contentCaseFlowService.selectContentCaseFlowList(contentCaseFlow);
        return getDataTable(list);
    }

    /**
     * 导出流程主体列表
     */
    @PreAuthorize("@ss.hasPermi('contentCaseFlow:contentCaseFlow:export')")
    @Log(title = "流程主体", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ContentCaseFlow contentCaseFlow)
    {
        List<ContentCaseFlow> list = contentCaseFlowService.selectContentCaseFlowList(contentCaseFlow);
        ExcelUtil<ContentCaseFlow> util = new ExcelUtil<ContentCaseFlow>(ContentCaseFlow.class);
        util.exportExcel(response, list, "流程主体数据");
    }

    /**
     * 获取流程主体详细信息
     */
    @PreAuthorize("@ss.hasPermi('contentCaseFlow:contentCaseFlow:query')")
    @GetMapping(value = "/{flowId}")
    public AjaxResult getInfo(@PathVariable("flowId") Long flowId)
    {
        return success(contentCaseFlowService.selectContentCaseFlowByFlowId(flowId));
    }

    /**
     * 新增流程主体
     */
    @PreAuthorize("@ss.hasPermi('contentCaseFlow:contentCaseFlow:add')")
    @Log(title = "流程主体", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ContentCaseFlow contentCaseFlow)
    {
        contentCaseFlow.setCreateBy(getUsername());
        return toAjax(contentCaseFlowService.insertContentCaseFlow(contentCaseFlow));
    }

    /**
     * 修改流程主体
     */
    @PreAuthorize("@ss.hasPermi('contentCaseFlow:contentCaseFlow:edit')")
    @Log(title = "流程主体", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContentCaseFlow contentCaseFlow)
    {
        contentCaseFlow.setUpdateBy(getUsername());
        return toAjax(contentCaseFlowService.updateContentCaseFlow(contentCaseFlow));
    }

    /**
     * 删除流程主体
     */
    @PreAuthorize("@ss.hasPermi('contentCaseFlow:contentCaseFlow:remove')")
    @Log(title = "流程主体", businessType = BusinessType.DELETE)
	@DeleteMapping("/{flowIds}")
    public AjaxResult remove(@PathVariable Long[] flowIds)
    {
        return toAjax(contentCaseFlowService.deleteContentCaseFlowByFlowIds(flowIds));
    }
}
